/**
 * Created by mapbar_front on 2019/7/5.
 */
function EventTarget(){
    this.handlers={}
}

EventTarget.prototype = {
    addHandler: function(type,handler){
        console.log('handler',handler);
        //this.handlers[type] = handler;
        if(typeof this.handlers[type] == 'undefined'){
            this.handlers[type] = [];
        }
        this.handlers[type].push(handler);
    },
    fire: function(event){
        var handlers = this.handlers[event.type];
        console.log('handlers',handlers);
        for(var i=0;i<handlers.length;i++){
            handlers[i](event.message);
        }
    },
    addMoveEvent: function(type,handler){
        if(this.handlers[type] instanceof Array){
            var handlers = this.handlers[type];
            for(var i=0;i<handlers.length;i++){
                if(handlers[i] === handler){
                    break;
                }
            }
            handlers.splice(i,1);
        }
    }
}
var target = new EventTarget();

export default target;